import { Link, useLocalSearchParams } from 'expo-router';
import {
ActivityIndicator,
Pressable,
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';
import { useOffice } from '@/features/offices/hooks/useOffice';
import { useFavoriteOffices } from '@/features/offices/hooks/useFavoriteOffices';
import { StatusMessage } from '@/shared/ui/StatusMessage';
import { useOfficeAvailability } from '@/features/reservations/hooks/useOfficeAvailability';
export default function OfficeDetailScreen() {
const params = useLocalSearchParams<{ officeId: string }>();
const officeId = typeof params.officeId === 'string' ? params.officeId : undefined;
const { office, loading, error, reload } = useOffice(officeId);
const {
favoriteOfficeIdsSet,
favoritesError,
pendingOfficeId,
toggleFavorite,
} = useFavoriteOffices();
const {
selectedDate,
reservations,
loading: loadingAvailability,
error: availabilityError,
setSelectedDate,
} = useOfficeAvailability(officeId);
if (loading) {
return (
);
}
if (error || !office) {
return (
{error ?? 'No se pudo cargar la oficina'}
Reintentar
Volver a espacios
);
}
return (
{office.name}
{
void toggleFavorite(office.id);
}}
disabled={pendingOfficeId === office.id}
>
{pendingOfficeId === office.id
? '...'
: favoriteOfficeIdsSet.has(office.id)
? '★'
: '☆'}
{favoritesError ? : null}
{availabilityError ? : null}
Ubicación
{office.location}
Capacidad
{office.capacity} personas
{office.description ? (
<>
Descripción
{office.description}
>
) : null}
Disponibilidad
Fecha
Consulta los horarios ocupados para esa fecha
{loadingAvailability ? (
) : availabilityError ? null : reservations.length === 0 ? (
No hay bloques ocupados para esta fecha
) : (
{reservations.map((reservation) => (
{reservation.startTime} - {reservation.endTime}
Ocupado
))}
)}
Reservar este espacio
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
gap: 16,
},
center: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 24,
gap: 12,
},
title: {
fontSize: 28,
fontWeight: '700',
flex: 1,
},
header: {
flexDirection: 'row',
alignItems: 'center',
gap: 12,
},
card: {
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 12,
padding: 16,
gap: 10,
},
label: {
fontSize: 14,
fontWeight: '700',
color: '#444',
},
sectionTitle: {
fontSize: 20,
fontWeight: '700',
marginBottom: 4,
},
value: {
fontSize: 16,
color: '#111',
},
input: {
borderWidth: 1,
borderColor: '#ccc',
borderRadius: 10,
paddingHorizontal: 14,
paddingVertical: 12,
marginTop: 4,
},
helper: {
color: '#666',
fontSize: 12,
},
availabilityList: {
gap: 10,
marginTop: 8,
},
availabilityItem: {
borderWidth: 1,
borderColor: '#d9e5d4',
backgroundColor: '#f3faf1',
borderRadius: 10,
padding: 12,
gap: 4,
},
availabilityTime: {
fontSize: 16,
fontWeight: '600',
color: '#1f3a1a',
},
availabilityStatus: {
color: '#336b2f',
fontSize: 13,
},
availableText: {
color: '#2e7d32',
marginTop: 8,
},
button: {
backgroundColor: '#1f6feb',
paddingVertical: 14,
borderRadius: 10,
alignItems: 'center',
},
secondaryButton: {
backgroundColor: '#555',
paddingVertical: 14,
paddingHorizontal: 16,
borderRadius: 10,
alignItems: 'center',
},
favoriteButton: {
width: 44,
height: 44,
borderRadius: 22,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#eef2f6',
},
favoriteButtonActive: {
backgroundColor: '#ffe8a3',
},
favoriteButtonText: {
fontSize: 22,
color: '#8a6700',
},
buttonText: {
color: '#fff',
fontWeight: '600',
},
error: {
color: 'red',
textAlign: 'center',
},
});